package com.iguo.tube;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.po.TableFill;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.util.Arrays;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    AutoGenerator autoGenerator = new AutoGenerator();

    DataSourceConfig dataSourceConfig = new DataSourceConfig();
    dataSourceConfig.setDbType(DbType.MYSQL);
    dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
    dataSourceConfig.setUsername("root");
    dataSourceConfig.setPassword("20040302gyx");
    dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/tube");
    autoGenerator.setDataSource(dataSourceConfig);

    GlobalConfig globalConfig = new GlobalConfig();
    globalConfig.setOpen(false);
    globalConfig.setOutputDir(System.getProperty("user.dir")+"/src/main/java");
    globalConfig.setAuthor("iGuo");
    globalConfig.setServiceName("%sService");
    autoGenerator.setGlobalConfig(globalConfig);

    PackageConfig packageConfig = new PackageConfig();
    packageConfig.setParent("com.iguo.tube");
    packageConfig.setEntity("model");
    packageConfig.setMapper("dao");
    packageConfig.setController("controller");
    packageConfig.setService("service");
    packageConfig.setServiceImpl("service.impl");
    autoGenerator.setPackageInfo(packageConfig);

    StrategyConfig strategyConfig = new StrategyConfig();
    strategyConfig.setEntityLombokModel(true);
    strategyConfig.setNaming(NamingStrategy.underline_to_camel);
    strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
    strategyConfig.setInclude("point");
    //TableFill tableFill1 = new TableFill("in_time", FieldFill.INSERT);
    //TableFill tableFill2 = new TableFill("out_time", FieldFill.INSERT);
    //TableFill tableFill3 = new TableFill("sign_time", FieldFill.INSERT);
    //List<TableFill> list = Arrays.asList(tableFill1,tableFill2,tableFill3);
    //strategyConfig.setTableFillList(list);
    autoGenerator.setStrategy(strategyConfig);

    autoGenerator.execute();
  }
}
